package coolapk.cj.cj.utils;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

/**
 * @author wenjunjun9
 * @created 2021-02-16 19:53
 * @description
 */
@Slf4j
public class BindingResultUtil {

    public static void apply(BindingResult result) {
        List<FieldError> fieldErrors = result.getFieldErrors();
        if (CollectionUtils.isNotEmpty(fieldErrors)) {
            StringBuilder sb = new StringBuilder();
            fieldErrors.forEach(item -> {
                sb.append(item.getDefaultMessage()).append(",");
                throw new IllegalArgumentException(sb.toString());
            });
        }
    }
}
